package com.demo;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import com.utils.ConstantUtil;
import com.utils.HttpHelper;
import com.utils.HttpResponse;
import com.utils.JsonUtil;

/**
 * 榆钱树支付/代付查询接口
 *
 * @date: 2017-5-5 下午5:23:28 
 * @author 任帅
 */
public class QueryOrderTest {
	
	public static void main(String[] args) {
		queryOrder();
	}
	
	public static void queryOrder(){
		try {
		EncryptManager encryptManager = new EncryptManager();
		encryptManager.initEncrypt();

		String urlString = ConstantUtil.TESTURL;

		Map<String, String> resMap = new HashMap<String, String>();
		
		//支付订单查询
		//resMap.put("TradeCode", "QueryOrder");
		
		//代付订单查询
		resMap.put("TradeCode", "QueryPayment");
		
		resMap.put("Version", ConstantUtil.VERSION);
		resMap.put("MobKey", encryptManager.getMobKey());
		
		//加密参数：具体字段参考文档
		resMap.put("MerchantId", encryptManager.getEncryptDES(ConstantUtil.MERCHANTID));  //商户号
		
		resMap.put("MerchOrderId", encryptManager.getEncryptDES("CZBH_2017052300000041"));//商户订单号
		
		//签名  签名参数： 具体字段参考文档
		//TradeCode,mobKey
		String[] signNames = {"TradeCode", "MobKey"};
		resMap.put("sign", encryptManager.getReqSign(signNames, resMap));

		// 发送请求
		String reqStr = "reqJson=" + JsonUtil.map2Json(resMap);
		
		
		HttpResponse resp = HttpHelper.doHttp(urlString, "POST","UTF-8", reqStr, "600000");
			
		System.out.println(resp);
		
		String body = resp.getBody();
		Map map = JsonUtil.jsonToMap(body);
		Set<String> set = map.keySet();
		for(Iterator<String> iter = set.iterator(); iter.hasNext();){
			String key = (String)iter.next();
		    String value = (String)map.get(key);
		    System.out.println(key+"===="+value);
		}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
